import Vue from 'vue'
import Vuex from 'vuex'

// 按需导入存储方法
import { setItem, getItem } from '@/utils/storage'

Vue.use(Vuex)

// 定义常量存储tokenkey
const TOKEN_KEY = 'user_token'

export default new Vuex.Store({
  state: {
    userToken: getItem(TOKEN_KEY)
  },
  mutations: {
    setUserToken(state, data) {
      state.userToken = data

      // 同时存入本地,实现持久化
      // console.log(data)
      setItem(TOKEN_KEY, data)
    }
  },
  actions: {},
  modules: {}
})
